﻿namespace HuaWei.CommClass
{
    using System;
    using System.Collections.Generic;
    using System.Management;

    public static class SerialNumber
    {
        public static List<string> GetSerialNumber()
        {
            List<string> list = new List<string>();
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDiskToPartition");
            foreach (ManagementObject obj2 in searcher.Get())
            {
                smethod1(obj2["Dependent"].ToString());
                string str = smethod1(obj2["Antecedent"].ToString()).Split(new char[] { ',' })[0].Remove(0, 6).Trim();
                ManagementObjectSearcher searcher2 = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
                foreach (ManagementObject obj3 in searcher2.Get())
                {
                    if ((obj3["Name"].ToString() == (@"\\.\PHYSICALDRIVE" + str)) & (obj3["InterfaceType"].ToString() == "USB"))
                    {
                        list.Add(smethod(obj3["PNPDeviceID"].ToString()));
                    }
                }
            }
            return list;
        }

        private static string smethod(string str)
        {
            string[] strArray = str.Split(new char[] { '\\' });
            int index = strArray.Length - 1;
            return strArray[index].Split(new char[] { '&' })[0];
        }

        private static string smethod1(string str)
        {
            int index = str.IndexOf("\"");
            int num2 = str.IndexOf("\"", (int) (index + 1));
            return str.Substring(index + 1, (num2 - index) - 1);
        }
    }
}

